local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent());
local CallBackManager = CommonOHOH.load.CallBackManager();

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

	self.player=_G.client.local_player
	self.SynTool=self.player:GetComponent(_G.CommonOHOH.load.Common_ActionSynchronize());

    -- -- 将操作同步到服务器
    -- self.parent.Syn2ServerEvent:Connect(function(tagInfo,sendInfo)
    --     local guid=nil
    --     local flyTime=sendInfo.flytime
    --     local pos=tagInfo.pos
    --     if tagInfo.obj then
    --         guid=tagInfo.obj:GetGuid()
    --     end
		
    --     self.SynTool:Push(self:GetWeaponAttackData(guid,flyTime,pos))
    --     self.SynTool:SendNetData()
    -- end)

	CallBackManager:AddRbxConnect(self,self.parent.Syn2ServerEvent, function(obj,tagInfo,sendInfo)
		local guid=nil
        local flyTime=sendInfo.flytime
        local pos=tagInfo.pos
        if tagInfo.obj then
            guid=tagInfo.obj:GetGuid()
        end
		
        self.SynTool:Push(self:GetWeaponAttackData(guid,flyTime,pos))
        self.SynTool:SendNetData()
    end);


end;

function M.GetWeaponAttackData(self,mguid,flyTime,tagPos)
	return  {
		 actionId= "SynWeaponOP", --组件上的函数
		 class="Common_UsingWeaponCtrl", --r组件
		 isCharacter=true,-- true 为Character上的组件，默认是player
		 arg={
			 equipId=self.parent:GetEquipId(),
			 actionId="Syn2Client",
			 arg={
				guid=mguid,
				flyTime=flyTime,
				pos=tagPos
			 }
		 }
	 }
end

function M.dtor(self)
	M.super.dtor(self);
end;


return M

